package com.apes.fn.fico.prefetch.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.fn.fico.reimbursement.model.FeeType;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @Title: PrefetchExpenseLedger
 * @Description: 预提费用总账
 * @author: ZhengZeXian
 * @create: 2022年2月15日13:41:32
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PrefetchExpenseLedger.CONST_TABLE_NAME)
public class PrefetchExpenseLedger extends BaseModel {

    public static final String CONST_TABLE_NAME = "fn_prefetch_expense_ledger";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "预提费用总账", padding = 7)
    @Comment("预提费用总账编码")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "prefetch_expense_id", referencedColumnName = "id")
    @Comment("预提费用")
    private PrefetchExpense prefetchExpense;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "duty_center_id", referencedColumnName = "id")
    @Comment("成本中心")
    private DutyCenter dutyCenter;

    @Comment("公司")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private PartyRole company;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fee_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private FeeType feeType;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Column(name = "fiscal_year")
    @Comment("财务年度")
    private Date fiscalYear;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "accountant_month")
    @Comment("会计月份")
    private Date accountantMonth;

    @Column(name = "amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("预提金额")
    private double amount = 0;

}
